package graph;

/**
 * Created by fengliejv on 2021/12/19.
 */
public class FindTheTownJudge997 {
    public int findJudge(int n, int[][] trust) {
        int[] inDegree = new int[n];
        int[] outDegree = new int[n];
        for (int i = 0; i < trust.length; i++) {
            outDegree[trust[i][0]-1]++;
            inDegree[trust[i][1]-1]++;
        }
        for (int i = 0; i < n; i++) {
            if(inDegree[i]==n-1&&outDegree[i]==0){
                return i+1;
            }
        }
        return -1;
    }
}
